package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.isVisible
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.util.DownloadProgressView
import com.github.lzyzsd.circleprogress.DonutProgress
import me.hgj.jetpackmvvm.base.appContext

/**
 * @Author      : hxw
 * @Date        : 2024/6/17 17:34
 * @Describe    :
 */
class RxDialogProgressBar(context: Context?) : RxDialog(context!!) {

    private lateinit var donut_progress: DonutProgress
    private lateinit var tvProgress: AppCompatTextView
    private lateinit var downloadProgressView: DownloadProgressView

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_progressbar, null)
        donut_progress = dialogView.findViewById(R.id.donut_progress)
        tvProgress = dialogView.findViewById(R.id.tvProgress)
        downloadProgressView = dialogView.findViewById(R.id.downloadProgressView)

        setContentView(dialogView)
    }

    @SuppressLint("SetTextI18n")
    fun setProgress(title: String, percent: Float) {
        tvProgress.text = String.format("$title:   %.1f", percent) + "%"
    }

    fun setProgressInt(progress: Int) {
        downloadProgressView.isVisible = true
        tvProgress.text = appContext.getString(R.string.Percent)
        //手动设置当前进度
        downloadProgressView.progress = progress
        //设置进度监听
        downloadProgressView.setOnProgressUpdateListener { pg -> }
    }
}